package org.wu.framework.inner.lazy.orm.solon.config;

import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Condition;
import org.noear.solon.annotation.Configuration;
import org.wu.framework.lazy.orm.core.config.LazyOperationAttribute;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.method.LazyOperationParameter;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.method.ddl.*;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.method.dml.*;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.method.dql.*;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.method.interceptor.SqlInterceptor;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.method.interceptor.SqlInterceptorAdapter;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.translation.adapter.LazyTranslationAdapter;

import java.util.List;

/**
 * @author : Jiawei Wu
 * @version 1.0
 * describe :
 * @date : 2021/1/24 5:19 下午
 */
@Slf4j
@Configuration
public class LazyORMMethodSolonAutoConfiguration {

    /**
     * describe  sql 拦截器适配器
     *
     * @param sqlInterceptorList 拦截器
     * @author Jia wei Wu
     * @date 2022/7/16 23:07
     **/

    @Condition(onMissingBean = SqlInterceptorAdapter.class)
    @Bean
    public SqlInterceptorAdapter sqlInterceptorAdapter(List<SqlInterceptor> sqlInterceptorList) {
        for (SqlInterceptor sqlInterceptor : sqlInterceptorList) {
            log.info("添加Lazy sql 拦截器:{}", sqlInterceptor.getClass().getName());
        }

        return new SqlInterceptorAdapter(sqlInterceptorList);
    }
    /**
     * describe  sql 拦截器适配器
     *
     * @param lazyOperationAttribute 配置信息
     * @param lazyTranslationAdapter 转译适配器
     * @param sqlInterceptorAdapter  sql 拦截器
     * @author Jia wei Wu
     * @date 2022/7/16 23:07
     **/

    @Condition(onMissingBean = LazyOperationParameter.class)
    @Bean
    public LazyOperationParameter lazyOperationParameter(LazyOperationAttribute lazyOperationAttribute,
                                                         SqlInterceptorAdapter sqlInterceptorAdapter,
                                                         LazyTranslationAdapter lazyTranslationAdapter) {
        return new LazyOperationParameter(lazyOperationAttribute, sqlInterceptorAdapter, lazyTranslationAdapter);
    }

    /**
     * describe 创建表结构
     *
     * @author Jia wei Wu
     * @date 2022/7/15 22:38
     **/
    @Condition(onMissingBean = LazyOperationMethodCreateTable.class)
    @Bean
    public LazyOperationMethodCreateTable lazyOperationMethodCreateTable(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodCreateTable(lazyOperationParameter);
    }

    /**
     * describe 创建表结构
     *
     * @author Jia wei Wu
     * @date 2022/7/15 22:38
     **/
    @Condition(onMissingBean = LazyOperationMethodCreateTableEndpoint.class)
    @Bean
    public LazyOperationMethodCreateTableEndpoint lazyOperationMethodCreateTableEndpoint(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodCreateTableEndpoint(lazyOperationParameter);
    }


    /**
     * describe  执行操作
     *
     * @author Jia wei Wu
     * @date 2022/7/15 22:38
     **/
    @Condition(onMissingBean = LazyOperationMethodExecute.class)
    @Bean
    public LazyOperationMethodExecute lazyOperationMethodExecute(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodExecute(lazyOperationParameter);
    }

    /**
     * describe 执行分页操作
     *
     * @author Jia wei Wu
     * @date 2022/7/15 22:38
     **/

    @Condition(onMissingBean = LazyOperationMethodExecutePage.class)
    @Bean

    public LazyOperationMethodExecutePage lazyOperationMethodExecutePage(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodExecutePage(lazyOperationParameter);
    }

    /**
     * describe 执行返回一条数据
     *
     * @author Jia wei Wu
     * @date 2022/7/15 22:38
     **/

    @Condition(onMissingBean = LazyOperationMethodExecuteOne.class)
    @Bean

    public LazyOperationMethodExecuteOne lazyOperationMethodExecuteOne(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodExecuteOne(lazyOperationParameter);
    }

    /**
     * describe 自定义数据库持久层操作方法执行SQL
     *
     * @param lazyOperationParameter 操作配置
     * @author Jia wei Wu
     * @date 2022/7/15 22:38
     **/

    @Condition(onMissingBean = LazyOperationMethodExecuteSQL.class)
    @Bean

    public LazyOperationMethodExecuteSQL lazyOperationMethodExecuteSQL(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodExecuteSQL(lazyOperationParameter);
    }

    /**
     * describe 执行SQL  自定义数据库持久层操作方法对Bean执行SQL
     *
     * @param lazyOperationParameter 操作配置
     * @author Jia wei Wu
     * @date 2022/7/15 22:38
     **/

    @Condition(onMissingBean = LazyOperationMethodExecuteSQLForBean.class)
    @Bean

    public LazyOperationMethodExecuteSQLForBean lazyOperationMethodExecuteSQLForBean(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodExecuteSQLForBean(lazyOperationParameter);
    }

    /**
     * describe 自定义数据库持久层操作方法插入
     *
     * @param lazyOperationParameter 操作配置
     * @author Jia wei Wu
     * @date 2022/7/15 22:38
     **/

    @Condition(onMissingBean = LazyOperationMethodInsert.class)
    @Bean

    public LazyOperationMethodInsert lazyOperationMethodInsert(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodInsert(lazyOperationParameter);
    }

    /**
     * describe 自定义数据库持久层操作方法插入或更新
     *
     * @param lazyOperationParameter 操作配置
     * @author Jia wei Wu
     * @date 2022/7/15 22:38
     **/

    @Condition(onMissingBean = LazyOperationMethodSaveOrUpdate.class)
    @Bean

    public LazyOperationMethodSaveOrUpdate lazyOperationMethodSaveOrUpdate(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodSaveOrUpdate(lazyOperationParameter);
    }

    /**
     * describe 分页查询
     *
     * @param lazyOperationParameter 操作配置
     * @author Jia wei Wu
     * @date 2022/7/15 22:38
     **/

    @Condition(onMissingBean = LazyOperationMethodPage.class)
    @Bean

    public LazyOperationMethodPage lazyOperationMethodPage(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodPage(lazyOperationParameter);
    }

    /**
     * describe 完善表
     *
     * @param lazyOperationParameter 操作配置
     * @author Jia wei Wu
     * @date 2022/7/15 22:38
     **/

    @Condition(onMissingBean = LazyOperationMethodPerfect.class)
    @Bean

    public LazyOperationMethodPerfect lazyOperationMethodPerfect(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodPerfect(lazyOperationParameter);
    }

    /**
     * describe 根据ID更新  自定义数据库持久层操作方法我选择列表
     *
     * @param lazyOperationParameter 操作配置
     * @author Jia wei Wu
     * @date 2022/7/15 22:38
     **/

    @Condition(onMissingBean = LazyOperationMethodSelectList.class)
    @Bean

    public LazyOperationMethodSelectList lazyOperationMethodSelectList(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodSelectList(lazyOperationParameter);
    }

    /**
     * describe 更新表
     *
     * @author Jia wei Wu
     * @date 2022/7/15 22:38
     **/

    @Condition(onMissingBean = LazyOperationMethodUpdateTable.class)
    @Bean
    public LazyOperationMethodUpdateTable lazyOperationMethodUpdateTable(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodUpdateTable(lazyOperationParameter);
    }

    /**
     * describe 更新表
     *
     * @author Jia wei Wu
     * @date 2022/7/15 22:38
     **/

    @Condition(onMissingBean = LazyOperationMethodUpdateTableEndpoint.class)
    @Bean
    public LazyOperationMethodUpdateTableEndpoint lazyOperationMethodUpdateTableEndpoint(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodUpdateTableEndpoint(lazyOperationParameter);
    }

    /**
     * describe upsert 操作
     *
     * @param lazyOperationParameter 操作配置
     * @author Jia wei Wu
     * @date 2022/7/15 22:38
     **/

    @Condition(onMissingBean = LazyOperationMethodUpsert.class)
    @Bean

    public LazyOperationMethodUpsert lazyOperationMethodUpsert(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodUpsert(lazyOperationParameter);
    }



    /**
     * describe insert map 操作
     *
     * @param lazyOperationParameter 操作配置
     * @author Jia wei Wu
     * @date 2022/7/15 22:38
     **/

    @Condition(onMissingBean = LazyOperationMethodWeakInsert.class)
    @Bean

    public LazyOperationMethodWeakInsert lazyOperationMethodInsertMap(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodWeakInsert(lazyOperationParameter);
    }


    /**
     * describe upsert map 操作
     *
     * @param lazyOperationParameter 操作配置
     * @author Jia wei Wu
     * @date 2022/7/15 22:38
     **/

    @Condition(onMissingBean = LazyOperationMethodWeakUpsert.class)
    @Bean

    public LazyOperationMethodWeakUpsert lazyOperationMethodUpsertMap(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodWeakUpsert(lazyOperationParameter);
    }
    /**
     * describe 去除null的字段
     *
     * @param lazyOperationParameter 操作配置
     * @author Jia wei Wu
     * @date 2022/7/15 22:38
     **/
    @Condition(onMissingBean = LazyOperationMethodUpsertRemoveNull.class)
    @Bean
    public LazyOperationMethodUpsertRemoveNull lazyOperationMethodUpsertRemoveNull(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodUpsertRemoveNull(lazyOperationParameter);
    }

    /**
     * describe 执行sql脚本
     *
     * @param lazyOperationParameter 操作配置
     * @author Jia wei Wu
     * @date 2022/7/16 23:07
     **/

    @Condition(onMissingBean = LazyOperationMethodScriptRunner.class)
    @Bean
    public LazyOperationMethodScriptRunner lazyOperationMethodScriptRunner(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodScriptRunner(lazyOperationParameter);
    }

    /**
     * describe 执行 字符串 sql脚本
     *
     * @param lazyOperationParameter 操作配置
     * @author Jia wei Wu
     * @date 2022/7/16 23:07
     **/

    @Condition(onMissingBean = LazyOperationMethodStringScriptRunner.class)
    @Bean
    public LazyOperationMethodStringScriptRunner lazyOperationMethodStringScriptRunner(LazyOperationParameter lazyOperationParameter) {
        return new LazyOperationMethodStringScriptRunner(lazyOperationParameter);
    }




}
